import maya.cmds as cmds
import maya.mel as mel
import os, sys
import maya.OpenMaya as om
#import studio.maya.baseTools.checkInstance   as checkInstance

import core
reload(core)

def getThreshold():
    threshold = 0.001
    return threshold

def checkExistingCaches(assetRoot, *args, **kw):
    
    #get list of caches
    nodes = cmds.ls(type = 'diskCache')
    errorNodes = []
    
    # check if caches point to a directory
    for node in nodes:
        if cmds.attributeQuery('filename', n = node, exists = True):
            if cmds.getAttr('%s.filename' % node) != '':
                errorNodes.append(node)
                
    nodes = cmds.ls(type = 'cacheFile')
    errorNodes.extend(nodes)
        
    
    if len(errorNodes) == 0:
        return core.checkResult(allowPublish=True, msg="Everything is OK")
    else:
        return core.checkResult(allowPublish=False, msg="These nodes have caches already", nodes=errorNodes)
 
 
 